package com.psp.park.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.psp.park.model.ParkAdminVisitorBean;
import com.psp.park.model.VisitorBean;
import com.psp.park.persist.dao.VisitorDao;

@Repository
public class VisitorImpl extends BaseImpl implements VisitorDao {
	final String NAME_SPACE = NAME_SPACE_HEADER + ".VisitorMapper";

	@Override
	public VisitorBean selectOneByPhone(String account) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByPhone", account);
	}

	@Override
	public int insert(VisitorBean newuser) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", newuser);
	}

	@Override
	public VisitorBean selectOneByEmail(String account) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByEmail", account);
	}

	@Override
	public int selectCount(String uid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", uid);
	}

	@Override
	public List<VisitorBean> selectList(int page, int pageSize, String uid) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		where.put("aid", uid);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public int insertAdminVisitor(ParkAdminVisitorBean pav) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insertAdminVisitor", pav);
	}

	@Override
	public List<VisitorBean> selectByUids(Set<String> uids) {
		Map<String, Object> where = new HashMap<>();
		where.put("uids", uids);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectByUids", where);
	}

}
